import asunit.framework.TestCase;

import mockAS2.Matcher;
import mockAS2.mocks.ClassToBeMocked;

/**
 * Copyright (c) 2012 Gary Higham
 * Released under the MIT license
 * https://code.google.com/p/mock-as2/wiki/License
 *
 * Version: v0.1
 */
class mockAS2.MatcherTest extends TestCase {
	private var className : String = "tvpTestFramework.MatcherTest";
	private var dummy : ClassToBeMocked;
	
	public function MatcherTest(testMethod : String) {
		super(testMethod);
	}
	
	public function setUp() : Void {
		dummy = new ClassToBeMocked();
	}
	
	public function tearDown() : Void {
		delete dummy;
		dummy = null;
	}
	
	public function testInstanceOfMatch() : Void {
		assertEquals("Class should be instance of Dummy", true, createInstanceMatcher(ClassToBeMocked).performMatch(dummy));
	}
	
	public function testIncorrectInstanceMatch() : Void {
		assertEquals("Class should not be instance of MovieClip", false, createInstanceMatcher(MovieClip).performMatch(dummy));
	}
	
	public function testTypeOfMatch() : Void {
		assertTrue("Class should be type of object", createTypeOfMatcher("object").performMatch(dummy));
	}
	
	public function testTypeOfMatchIsCaseInsensitive() : Void {
		assertTrue("Class should be type of object", createTypeOfMatcher("ObjecT").performMatch(dummy));
	}

	public function testCustomFunctionMatch() : Void {
		var match : Matcher = new Matcher();
		match.customMatch(function(value : ClassToBeMocked) : Boolean { return value.return1() === 1;});
		assertTrue("Custom Match should be true", match.performMatch(dummy));
	}
	
	public function testCustomFunctionIncorrectMatch() : Void {
		var match : Matcher = new Matcher();
		match.customMatch(function(value : ClassToBeMocked) : Boolean { return value.return1() === 2;});
		assertFalse("Custom Match should be false", match.performMatch(dummy));
	}
	
	private function createInstanceMatcher(type : Object) : Matcher {
		var match : Matcher = new Matcher();
		match.isInstanceOf(type);
		return match;
	}
	
	private function createTypeOfMatcher(type : String) : Matcher {
		var match : Matcher = new Matcher();
		match.isTypeOf(type);
		return match;
	}
}
